//
//  UIImage+FNExtension.swift
//  FearfulNotification
//
//  Created by 筱鹏 on 2018/1/16.
//  Copyright © 2018年 筱鹏. All rights reserved.
//

import UIKit

extension UIImage {
    class func grayImage() -> UIImage {
        UIGraphicsBeginImageContext(CGSize(width: 0.5, height: 0.5))
        let ctx = UIGraphicsGetCurrentContext()
        ctx?.setFillColor(Theme.color.septationLine.cgColor)
        ctx?.fill(CGRect(x: 0, y: 0, width: 0.5, height: 0.5))
        let image = UIGraphicsGetImageFromCurrentImageContext()
        UIGraphicsEndImageContext()
        guard let newImg = image else {
            return UIImage()
        }
        return newImg
    }
    
    class func circle(fill fillColor: UIColor, radius: CGFloat) -> UIImage {
        let size = CGSize(width: radius * 2, height: radius * 2)
        
        UIGraphicsBeginImageContext(size)
        let ctx = UIGraphicsGetCurrentContext()
        ctx?.setFillColor(fillColor.cgColor)
        ctx?.fillEllipse(in: CGRect(x: 0, y: 0, width: size.width, height: size.height))
        
        let image = UIGraphicsGetImageFromCurrentImageContext()
        UIGraphicsEndImageContext()
        guard let newImg = image else {
            return UIImage()
        }
        return newImg
    }
    
    class func circle(stroke strokeColor: UIColor, radius: CGFloat) -> UIImage {
        let size = CGSize(width: radius * 2, height: radius * 2)
        
        UIGraphicsBeginImageContext(size)
        let ctx = UIGraphicsGetCurrentContext()
        
        let lineWidth: CGFloat = 2
        ctx?.setLineWidth(lineWidth)
        ctx?.setStrokeColor(strokeColor.cgColor)

        ctx?.addArc(center: CGPoint(x: radius, y: radius), radius: radius-lineWidth, startAngle: 0, endAngle: CGFloat(2 * Double.pi), clockwise: true)
        ctx?.drawPath(using: .stroke)
        
        let image = UIGraphicsGetImageFromCurrentImageContext()
        UIGraphicsEndImageContext()
        guard let newImg = image else {
            return UIImage()
        }
        return newImg
    }
}
